<template>
  <div>

    <el-dialog :title="form.id?'编辑页面':'新增页面'" :visible="showDialog" width="30%" @close="closeFn">
      <el-form ref="ruleForm" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name" />
        </el-form-item>
        <el-form-item label="邮箱">
          <el-input v-model="form.email" type="text" />
        </el-form-item>

        <el-form-item label="电话">
          <el-input v-model="form.phone" type="text" />
        </el-form-item>
        <el-form-item label="地址">
          <el-input v-model="form.address" type="text" />
        </el-form-item>
        <el-form-item label="描述" prop="desc">
          <el-input v-model="form.desc" type="text" />
        </el-form-item>
        <el-form-item label="图片">
          <Upload />
          <el-input v-model="form.image" type="text" />
        </el-form-item>

      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-row type="flex" justify="center">
          <el-button @click="closeFn">取 消</el-button>
          <el-button type="primary" @click="addClifty">确 定</el-button>
        </el-row>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { AddManger, OneManger, editManger } from '@/api/model/manger'
import Upload from '@/components/Upload'
export default {
  components: { Upload },
  props: {
    showDialog: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      form: {
        name: '',
        email: '',
        phone: '',
        address: '',
        desc: '',
        image: '',
        id: null
      },
      rules: {
        name: [
          { required: true, message: '请输入名称', trigger: 'blur' }
        ],
        desc: [
          { required: true, message: '请输入描述', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    // 编辑
    async EditId(id) {
      console.log(id)
      this.form.id = id
      // delMande(id)
      const res = await OneManger(id)
      // console.log(res)
      this.form = res.data
    },
    // 新增
    async addClifty() {
      if (this.form.id) {
        const res = await editManger(this.form)
        console.log(res)
        this.closeFn()
      } else {
        await AddManger(this.form)
      }
      this.$emit('updata')
      // console.log(res)
      this.closeFn()
    },
    closeFn() {
      this.$emit('update:showDialog', false)
      this.form = {
        name: '',
        email: '',
        phone: '',
        address: '',
        desc: '',
        image: ''
      }
      this.$refs.ruleForm.resetFields()
    }
  }

}
</script>
<style>

</style>
